<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<#include "/views/ftl/base/manager_include.ftl">
<head>
<title>权限</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
		
<link rel="stylesheet" type="text/css" href="${basePath }easy/css/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${basePath }easy/css/themes/icon.css">
	 <!--<link rel="stylesheet" type="text/css" href="${basePath }easy/css/demo.css">-->
       <!--<script type="text/javascript" src="${basePath }easy/js/jquery.min.js"> </script>-->
	<script type="text/javascript" src="${basePath }easy/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${basePath }easy/js/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="${basePath }easy/js/datagrid-detailview.js"></script> 
<title></title>  
</head>  
<body style="background:#eef3f7;">
<#include "/views/ftl/base/head.ftl">
<div class="Main">
  <div class="dw">
<#include "/views/ftl/base/menu.ftl">
<#function a><#return "权限列表_List"></#function> 
<!-- 标题显示 -->
<div id="Title_bar" class="Rightbox fl">
 <!--导航-->
    <div class="Bread_crbs clear">
      <div class="Bread_crbs_img fl"></div>
      <div class="Bread_crbs_text fl">
      	<a href="javascript:void(0);"><span>权限设置</span></a>
      	<span class="fnt_famy">></span>
      	<a href="javascript:void(0);"><span>权限列表</span></a>
      </div>
    </div>
    
    
     <!--开始-->
	<table id="dg2"  title="权限列表" iconcls="icon-view" style="width:400px;height:280px;" fitColumns="true">    
    </table>
<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons">
	<div class="ftitle"></div>
	<form id="fm" method="post">
		 <div class="fitem">
			<label>权限名称:</label>
			<input id="name" class="easyui-validatebox" required="true" name="name" style="width:100px;">
		 </div>
		
	</form>
</div>
<div id="dlgdetil" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
		closed="true" buttons="#dlg-buttons2">
	<div class="ftitle"></div>
	<form id="fm2" method="post">
		<div class="fitem">
			<label>上&nbsp;&nbsp;&nbsp;&nbsp;级&nbsp;&nbsp;&nbsp;&nbsp;:</label>
			<input id="parent_id" class="easyui-validatebox" name="parent_id" style="width:100px;" readOnly="readonly">
	    	  
		</div>
		<div class="fitem">
			<label>名&nbsp;&nbsp;&nbsp;&nbsp;称&nbsp;&nbsp;&nbsp;&nbsp;:	</label>
			<input id="name1" class="easyui-validatebox" required="true" name="name" style="width:100px;">
	    	
		</select>
			
	    	  
		</div>
		<div class="fitem">
			<label>&nbsp;URL地&nbsp;址:</label>
			<input id="url1" class="easyui-validatebox" required="true" name="url" style="width:100px;">
		</div>
	
		
	</form>
</div>
<div id="dlg-buttons">
	<a  class="easyui-linkbutton" iconCls="icon-ok" onclick="saveBean()">保存</a>
	<a  class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close');">取消</a>
</div>

<div id="dlg-buttons2">
	<a  class="easyui-linkbutton" iconCls="icon-ok" onclick="saveBean2()">保存</a>
	<a  class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgdetil').dialog('close');">取消</a>
</div>
</div>
</div>
</div>

</body>
<script type="text/javascript">
function up(id,r)
{
  $.ajax({  
            url :"${basePath }manager/Authority_setUp",  
            type :'post',  
		    data : { 
				id : id,
				pid : r,
			}, 
            success:function(data){     
            if(r==null){
           		$("table#dg2").datagrid("reload");
			}
			else{
 				$("table#ddv"+r).datagrid("reload");}
             }  
         });  
}

function down(id,r){
  $.ajax({  
            url  : "${basePath }manager/Authority_setDown",  
            type : 'post',  
		    data : { 
				id : id,
				pid : r
			}, 
            success:function(data){   
             if(r==null){
                 $("table#dg2").datagrid("reload");
			  }
			 else{
 				$("table#ddv"+r).datagrid("reload");}
				 }  
          });  
}
$(document).ready(function() {

	InitGrid();

});
function InitGrid(queryData) {
	
    $('#dg2').datagrid({   //定位到Table标签，Table标签的ID是grid
        url: '${basePath }manager/Authority_findByTop',   //指向后台的Action来获取当前菜单的信息的Json格式的数据
        title: '权限列表',
        singleSelect:false,
        //selectOnCheck:false,
       // checkOnSelect:true,
        iconCls: 'icon-view',
        height: 650,
        width: function () { return document.body.clientWidth },
        nowrap: true,
        autoRowHeight: false,
        striped: true,
        collapsible: true,
        pagination: true,
        pageSize:15,
        pageList:[15,30,60,90],
        sortName: 'indexNo',    //根据某个字段给easyUI排序
        sortOrder: 'asc',
        rownumbers: true,
        remoteSort: false,
       // idField: 'id',
        queryParams: queryData,  //异步查询的参数
        columns: [[
            { field: 'ck', checkbox: true },   //选择
             { title: '权限名称', field: 'name', width: 100},
             { title: 'url地址', field: 'url', width: 100},
             { title: '创建时间', field: 'creationDate', width: 100 },
             { title: '修改时间', field: 'modificationDate', width: 100 },
             { title: '排序', field: 'id', width: 200,
  formatter:function(val){
					
					return "<span style='color:black;'>"+
					"<a href=javascript:up("+val+");>上移</a>&nbsp;"+ 
					"<a href=javascript:down("+val+");>下移</a>&nbsp;</span>";
					
					}  },
 { title: 'IndexNo', field: 'indexNo', width: 100 },
        ]],
        toolbar: [{
            id: 'btnAdd',
            text: '添加',
            iconCls: 'icon-add',
            handler: function () {
            	newBean();//实现添加记录的页面
            }
        }, '-', {
            id: 'btnEdit',
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                ShowEditOrViewDialog();//实现修改记录的方法
            }
        }, '-', {
            id: 'btnDelete',
            text: '删除',
            iconCls: 'icon-remove',
            handler: function () {
                Delete();//实现直接删除数据的方法
            }
        },  '-', {
            id: 'btnReload',
            text: '刷新',
            iconCls: 'icon-reload',
            handler: function () {
                //实现刷新栏目中的数据
                $("#dg2").datagrid("reload");
            }
        }],
      
        onDblClickRow: function (rowIndex, rowData) {
            $('#dg2').datagrid('uncheckAll');
            $('#dg2').datagrid('checkRow', rowIndex);
            ShowEditOrViewDialog();
        }
    });

    
    var p = $('#dg2').datagrid('getPager'); 
    $(p).pagination({ 
        pageSize: 15,//每页显示的记录条数，默认为10 
        pageList: [15,30,60,90],//可以设置每页记录条数的列表 
        beforePageText: '第',//页数文本框前显示的汉字 
        afterPageText: '页    共 {pages} 页', 
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录', 
    }); 
};




$('#dg2').datagrid({
	
	view: detailview,
	detailFormatter:function(index,row){
		return '<div style="padding:2px" ><table class="ddv'+index+'" id="ddv'+row.id+'" ></table></div>';
	},
	onExpandRow: function(index,row){
		var ddvv= $(this).datagrid('getRowDetail',index).find('table#ddv'+row.id);
		var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv'+index);
		ddv.datagrid({
			url:'${basePath }manager/Authority_findAuthorityChild?id='+row.id,
			fitColumns:true,
			singleSelect:true,
			rownumbers:true,
			loadMsg:'',
            sortName: 'indexNo',    //根据某个字段给easyUI排序
            sortOrder: 'asc',
            remoteSort: false,
			height:'1000',
		
			columns:[[
					
						{field:'name',title:'名称',width:100},
						{field:'url',title:'链接地址',width:100},
						{field:'creationDate',title:'创建时间',width:100},
						{field:'modificationDate',title:'修改时间',width:100},
  						{ title: '排序', field: 'id', width: 200,
  					formatter:function(val){
					return "<span style='color:black;'>"+
					"<a href=javascript:up("+val+","+row.id+");>上移</a>&nbsp;"+ 
					"<a href=javascript:down("+val+","+row.id+");>下移</a>&nbsp;</span>";
					}  },
 					{ title: 'IndexNo', field: 'indexNo', width: 100 },
			]],
			 toolbar: [{
		            id: 'btnAdd',
		            text: '添加',
		            iconCls: 'icon-add',
		            handler: function () {
		            	newBean2(row.id);//实现添加记录的页面
		            }
		        }, '-', {
		            id: 'btnEdit',
		            text: '修改',
		            iconCls: 'icon-edit',
		            handler: function () {
		                ShowEditOrViewDialog2(row.id);//实现修改记录的方法
		            }
		        }, '-', {
		            id: 'btnDelete',
		            text: '删除',
		            iconCls: 'icon-remove',
		            handler: function () {
		                Delete2(row.id);//实现直接删除数据的方法
		            }
		        },  '-', {
		            id: 'btnReload',
		            text: '刷新',
		            iconCls: 'icon-reload',
		            handler: function () {
		                //实现刷新栏目中的数据
		           ddvv.datagrid("reload");
		              
		            }
		        }],
		      
			onResize:function(){
				$('#dg2').datagrid('fixDetailRowHeight',index);
			},
			onLoadSuccess:function(){
				setTimeout(function(){
					$('#dg2').datagrid('fixDetailRowHeight',index);
				},0);
				
			} 
		});
		$('#dg2').datagrid('fixDetailRowHeight',index);
	}
});
	

function relod(){
	$('#dg2').datagrid('reload');
}

function  Delete(id){
	 var selectRows = $("table#dg2").datagrid('getSelections');   

       if(selectRows.length==0){  
           $.messager.alert("系统提示","请选择一条数据然后重试！","warning");  
           return;  
       }else{  
           $.messager.confirm("提示", "是否确认要当前所选中的数据？", function(r) {  
               if (r){  
                   var reportsIds= "";  
                   for( var i=0; i < selectRows.length; i++){  
                       reportsIds += selectRows[i].id;  
                     reportsIds += ",";  
                 }  
            
                   $.ajax({  
                       url:"${basePath }manager/Authority_DeleteAuthority?ids="+reportsIds,  
                       type:'post',  
                       success:function(data){   
                           if(data){                     
                               $.messager.alert('系统提示', '删除成功!');        
                              // $('#monthReportdlg').dialog('close');  
                              $("table#dg2").datagrid('reload');  
                              // selectRows.length=0;      
                           }else{  
                               $.messager.alert('系统提示', '删除失败!','warning');          
                              // $('#monthReportdlg').dialog('close');  
                              // $('#MonthReportTab').datagrid('reload');  
                            //   selectRows.length=0;  
                           }     
                       }  
                   });  
               }  
           }) ; 
       } 
       }
function  Delete2(id){
	 var selectRows = $("table#ddv"+id).datagrid('getSelections');   

     if(selectRows.length==0){  
         $.messager.alert("系统提示","请选择一条数据然后重试！","warning");  
         return;  
     }else{  
         $.messager.confirm("提示", "是否确认要当前所选中的数据？", function(r) {  
             if (r){  
                 var reportsIds= "";  
                 for( var i=0; i < selectRows.length; i++){  
                     reportsIds += selectRows[i].id;  
                   reportsIds += ",";  
               }  
          
                 $.ajax({  
                     url:"${basePath }manager/Authority_DeleteAuthority?ids="+reportsIds,  
                     type:'post',  
                     success:function(data){   
                         if(data){                     
                             $.messager.alert('系统提示', '删除成功!');        
                            // $('#monthReportdlg').dialog('close');  
                            $("table#ddv"+id).datagrid('reload');  
                            // selectRows.length=0;      
                         }else{  
                             $.messager.alert('系统提示', '删除失败!','warning');          
                            // $('#monthReportdlg').dialog('close');  
                            // $('#MonthReportTab').datagrid('reload');  
                          //   selectRows.length=0;  
                         }     
                     }  
                 });  
             }  
         }) ; 
     } 
       } 
	function ShowEditOrViewDialog(id){
	 	var row = $("table#dg2").datagrid('getSelected');
	 	 if(row==null){  
           $.messager.alert("系统提示","请选择一条数据然后重试！","warning");  
           return;  
       		}
	 if (row){
	 	$('#dlg').dialog('open').dialog('setTitle','编辑权限 ');
	 	$('#fm').form('load',row);
	 	url = '${basePath }manager/Authority_updateAuthority?id='+row.id;
			}
	 }
	 function ShowEditOrViewDialog2(id){
		 var row = $("table#ddv"+id).datagrid('getSelected');
		 if(row==null){  
	           $.messager.alert("系统提示","请选择一条数据然后重试！","warning");  
	           return;  
	       }
		 if (row){
		 	$('#dlgdetil').dialog('open').dialog('setTitle','编辑权限');
		 	$('#fm2').form('load',row);
			$('#fm2').find("#parent_id").val(id);
		 	url ='${basePath }manager/Authority_updateAuthority?id='+row.id;
		 	
		 
	}
}
function saveBean(){
	 $('#fm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(data){
				var result = eval('('+data+')');
				if (result.errorMsg){

					$.messager.show({
						title: 'Error',
						msg: result.errorMsg
					});
				} else {
					$('#dlg').dialog('close');
					  $("table#dg2").datagrid("reload");
					//	alert(result.titleId);
				
				}
			}
});
	 }
	 
	 
function saveBean2(){
	 $('#fm2').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(data){
				var result = eval('('+data+')');
				if (result.errorMsg){

					$.messager.show({
						title: 'Error',
						msg: result.errorMsg
					});
				} else {
					$('#dlgdetil').dialog('close');
					  $("table#ddv"+result.pid).datagrid("reload");
					//  alert(result.titleId);
				}
			}
});
	 }
function newBean(){
	$('#dlg').dialog('open').dialog('setTitle','新权限');
	$('#fm').form('clear');
	url = '${basePath }manager/Authority_addAuthority';
	
}
function newBean2(id){
	$('#dlgdetil').dialog('open').dialog('setTitle','新权限');
	$('#fm2').form('clear');
	$('#fm2').find("#parent_id").val(id);
	url = '${basePath }manager/Authority_addAuthorityChild?id=';
	url+=id;
}
	</script>
</html>